<?php
/**
 * Created by PhpStorm.
 * User: Thans
 * Date: 2018/5/21
 * Time: 下午7:24
 */

namespace app\admin\controller\view;

use app\admin\facade\Menu;
use app\common\controller\Admin;
use thans\auth\facade\Token;
use think\Db;
use think\facade\App;
use think\facade\Cache;
use think\facade\Config;

/**
 * @title 后台首页
 * Class IndexController
 * @package app\admin\controller
 */
class IndexController extends Admin
{
    public function index()
    {
        $uinfo = $this->uinfo;
        $g_id = isset($uinfo['group']['group_id']) ?: 0;
        $topMenu = Menu::getTopList([], $g_id)['data'];
        $this->assign('uinfo', $uinfo);
        $this->assign('topMenu', $topMenu);
        return $this->fetch();
    }

    public function dashboard()
    {
        $system_info = Cache::get('system_info');
        if (!$system_info) {
            $mysql = Db::query("select VERSION() as version");
            $mysql = $mysql[0]['version'];
            $mysql = empty($mysql) ? lang('UNKNOWN') : $mysql;
            $system_info = [
//            '网站授权' => '<span class="layui-badge layui-bg-orange">免费版</span><a style="padding: 10px;font-size: 12px;" href="http://www.uinge.com/ingephp/">立即购买专业版</a>',
                'IngePHP版本' => Config::get('inge.ig_version'),
                'THINKPHP版本' => App::version(),
                '系统' => PHP_OS,
                'PHP版本' => phpversion(),
                'MySql版本' => $mysql,
                '上传限制' => ini_get('upload_max_filesize'),
                '剩余空间' => round((@disk_free_space(".") / (1024 * 1024)), 2) . 'M',
                '开发手册' => '<a style="color:#1F98CA;" href="' . Config::get('inge.doc_url') . '">' . Config::get('inge.doc_url') . '</a>',
                'BUG反馈' => '<a style="color:#1F98CA;" href="' . Config::get('inge.bug_submit') . '">' . Config::get('inge.bug_submit') . '</a>',
            ];
            Cache::set('system_info', $system_info, 1800);
        }
        $app_info = [
            '产品名称' => Config::get('inge.app_name'),
            '研发团队' => 'Thans',
            '项目官网' => '<a target="_top" style="color:#1F98CA;" href="' . Config::get('inge.app_url') . '">' . Config::get('inge.app_url') . '</a>',
            '商务联系' => '<img src="http://cdn.inge.vip/thans.jpeg">',
            '为我点赞' => '<a target="_top" href=\'https://gitee.com/thans/ingephp/stargazers\'><img src=\'https://gitee.com/thans/ingephp/badge/star.svg?theme=white\' alt=\'star\'></img></a>',
            '开源地址' => '<a href=\'https://gitee.com/thans/ingephp\'><img src=\'https://gitee.com/thans/ingephp/widgets/widget_6.svg\' alt=\'Fork me on Gitee\'></img></a>',
        ];
        $this->assign('system_info', $system_info);
        $this->assign('app_info', $app_info);
        return $this->fetch();
    }
}
